/****************************************************************************

Force Engine v0.5

Creado: 28/03/08
Clase: Vertex Buffer.inl
Hecho by: German Battiston AKA Melkor

****************************************************************************/

//---------------------------------------------------------------------------
inline IndexBuffer::IndexBuffer()
:
m_pkDevice(NULL),
m_IndexBuffer(NULL)
{
	
}
//---------------------------------------------------------------------------
inline IndexBuffer::~IndexBuffer()
{
	
}
//---------------------------------------------------------------------------
inline bool IndexBuffer::Create( IDirect3DDevice9 * pkDevice,
								 bool bDynamic,
								 short iIndexCount,
								 short * pkIndexCollection )
{
	if(iIndexCount < 3)
	{
		return false;
	}

	m_pkDevice = pkDevice;

	m_sIndexCount = iIndexCount;

	HRESULT hr = pkDevice->CreateIndexBuffer( m_sIndexCount * sizeof(short),
    										  D3DUSAGE_WRITEONLY,
											  D3DFMT_INDEX16,
											  D3DPOOL_MANAGED,
											  &m_IndexBuffer,
											  NULL );


	void * pVertices;

	hr = m_IndexBuffer->Lock(0, m_sIndexCount * sizeof(short), (void **)&pVertices, 0);

	memcpy(pVertices, pkIndexCollection, sizeof(short) * m_sIndexCount);

	hr = m_IndexBuffer->Unlock();

	if(hr != D3D_OK)
	{
		return false;
	}

	return true;
}
//---------------------------------------------------------------------------
inline void IndexBuffer::Release()
{
	m_IndexBuffer->Release();
}
//---------------------------------------------------------------------------
inline void IndexBuffer::Bind()
{
	HRESULT hr;

	hr = m_pkDevice->SetVertexShader(NULL);
	hr = m_pkDevice->SetIndices(m_IndexBuffer);
}
//---------------------------------------------------------------------------
inline LPDIRECT3DINDEXBUFFER9 IndexBuffer::GetIndexBuffer()
{
	return m_IndexBuffer;
}
//---------------------------------------------------------------------------
inline unsigned int IndexBuffer::GetIndexCount()
{
	return m_sIndexCount;
}
//---------------------------------------------------------------------------